<?php


namespace app\api\model\wanlshop;


use think\Model;
use think\Request;

class Banner extends Model
{

    // 表名
    protected $name = 'wanlshop_banner';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];


    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function getModelList(){
        return [
            'index' => __('Model index'),
            //'optimal' => __('Model optimal'),
            //'groupon' => __('Model groupon'),
            //'vouchers' => __('Model vouchers'),
            //'nearby' => __('Model nearby'),
            //'home_activity' => __('Model Home_activity'),
        ];
    }

    public function getTypeList(){
        return [
            'none' => __('Type none'),
            'goods' =>  __('Type goods'),
            //'shop' =>  __('Type shop'),
            //'vouchers' => __('Type vouchers'),
        ];
    }
// getImagesAttr
    public function getImageAttr($value, $data){
        $request = Request::instance();
        if (substr($request->url(), 0, 4) == '/api' && strpos($request->url(),'addOrder') == false) {
            return cdnurl($value, true);
        }
        return $value;
    }
}